<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html >
	<head>
	<base href="<%=basePath%>"/>
    <link href="themes/css/ui.common.css" rel="stylesheet" type="text/css" />
    <link href="themes/css/ui.child.css" rel="stylesheet" type="text/css" />
    <link href="themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
    <link href="style/jquery_ui/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" />
    <link id="skin_css" type="text/css" rel="stylesheet" href="themes/css/ui.c.blue.css" />
    <link rel="stylesheet" type="text/css" href="themes/default/pagination.css" />
    <link href="themes/css/ui.selector.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.8.custom.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="Scripts/ui.tips.js" type="text/javascript"></script>
    <script src="Scripts/ui.default.js " type="text/javascript" charset="UTF-8"></script>
    <script src="Scripts/ui.admincp.js" type="text/javascript" charset="UTF-8"></script>
    <script src="Scripts/ui.objectSelector.js" type="text/javascript"></script>
 
 
    <script type="text/javascript">
        $(function () {
           switcher(); 
            getAllSelector();
            $("#receiverSelected").objectSelector({
                fromAjax: true,
                ajaxDataAction: "move!getPersonBySectionId.action",
                subGroupBuilder: subGroupBuilder,
                selectionResult: "#txt_Receiver",
                postArgBuilder: postArgBuilder
            });
            $.fn.objectSelector.initailCurrent("#text-container-inner", "#add_address");
            
             $("#btnSelectReceiver,#btnCloseSelector,#btnCloseSelectBar").click(function () {
                toggleSelector();
            });
        });
      function getSelectedPeople() {
            $.fn.objectSelector.pushSelectionsTo("#receiverSelected", "#txt_Receiver");
        }
        function subGroupBuilder(item) {
       	 
            var sectionId = item.archiveInfo.postInfo.sectionInfo.sectionId;
            var name = item.archiveInfo.staffName;
            var staffId = item.staffId;
            var info = item.archiveInfo.gender;
            var groupId = sectionId;
            return '<div class="groupItem"><a class="lm_addr" key="g' + sectionId + '" href="javascript:void(0)"><input type="button" class="move" />'
            + '<div class="arguementBar" key="g' + sectionId  + '" entityId="' + staffId + '" itemindex="0" title="">'
            + name + ' <span class="details Tips3">' + info + '</span></div></a></div>';
        }
        function postArgBuilder(sectionId)
        {
              return {sectionId:sectionId};
        }

        function getAllSelector() {
            $("#btnSend").click(function () {
                var result = "";
                $(".text-display").each(function (i) {
                    result += ($(this).attr("value")+":"+$(this).attr("name") + ",")
                });
                
               var sectionId=$("#sectionSelector").val();
		var postId=$("#postSelector").val();
		var comments=$("#txt_Description").val();
		
		var jsonString = {
					"result":result,
					"sectionId":sectionId,
					"postId":postId,
					"comments":comments
				} ;
				
				var jsonStr = $.toJSON(jsonString);
		
				$.post("move!add.action",
				{"jsonStr":jsonStr},
				function(data){
				
				$("#tip").text("添加成功!");
				},
				"json");
            });

        }   
            function switcher() {
				$("#sectionSelector").change( function() {
					var sectionId = $(this).val();
					$.post("move!queryPostBySection.action", {
						"sectionId" :sectionId
					}, function(data) {
						//对应的物资信息添加到select中
						$("#postSelector").html("").append(data);
						});
					},

		"html");
	}
	
	function clearPostSelector(){
		$("#postSelector").html("").append("<option value=\"\">-请先选择部门-</option>" );
	}
    </script>
</head>
<body>
		 <div class="PageChild_Title">
        <img src=" themes/images/default/icons/archives.png" class="PageChild_Tbtnpic" />
        <span class="PageChild_separate"></span><span class="PageChild_TbtnText">
            <h2>
                创建人员调度</h2>
        </span><span class="PageChild_separate"></span>
        <div id="marker" class="red-tips">
        </div>
        <div class="clear">
        </div>
    </div>
    <div>
        <div>
            <table id="topTab" class="tb tb2" border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr class="header">
                    <td class="mtd" style="width: 88px;">
                        <span><a href="javascript:void(0);" id="btnSelectReceiver" title="单击选择调度人员">人员列表:</a> </span>
                    </td>
                    <td>
                        <div class="text-container"  >
                            <ul class="text-container-inner objectSelector-result" id="txt_Receiver">
                                
                            </ul>
                        </div>
                    </td>
                </tr>
            </table>
            <div id="receiverSelected" style="display: none;">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td valign="top">
                            <span>选择人员:</span>
                            <div class="Box leftContainer" id="add_address_Left" style="overflow-y: auto;height:362px;">
                                <div class="lm_sbar hiddenObject">
                                    <input type="button" class="lm_sopen" style="" id="btn_UserSearch" />
                                    <div>
                                        <input type="text" id="txt_SearchText" style="height: 19px;" value="查找人员..." class="txt" />
                                    </div>
                                </div>
                                <div id="lb_SearchTips" style="display: none">
                                    查找到以下结果:
                                    <div id="lm_ifNullTips">
                                    </div>
                                </div>
                                <div class="lm_panel hiddenObject" id="lm_SB" style="">
                                </div>
                                <div class="lm_panel" id="lm_ListB" style="height:100%;">
                                <s:iterator value="sectionList" var="item"> 
                                        <div class="groupclose" key="g${item.sectionId }" entityId="${item.sectionId }" open="false" hasload="false" style="font-weight: bolder;">
                                        <div style="padding: 2px 0pt 1px; background: none repeat scroll 0% 0% rgb(255, 255, 255);
                                            color: black;" onmouseout="this.style.background='#fff'" onmouseover="this.style.background='#ffeec2'"
                                            class="">   <div class="clear"></div>
                                            <span class="Tips3 lm_helper">全部添加</span>
                                            <div class="lm_ca" title="${item.sectionName}">
                                                <input type="button" class="lm_ico" />
                                                ${item.sectionName} <span class="Tips3 groupItemCountTips"  id="groupTips_${item.sectionId }">(未加载)</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="groupsub" key="g${item.sectionId }">
                                    </div>
                                </s:iterator>
                                </div>
                            </div>
                        </td>
                        <td align="center" style="padding: 5px;">
                            <img alt="" src="style/arrow_left.gif" />
                        </td>
                        <td valign="top">
                            <span>已选择(<span id="count_Receiver"  class="receiverCounter">0</span>)</span>
                            <div id="add_address" style="overflow-y: auto; height: 362px; padding-left: 3px;"
                                class="Box objectSelectorContainer rightContainer">
                            </div>
                        </td>
                    </tr>
                </table>
                <div class="msgBar" id="inSelector">
                    <input type="button" name="name" id="btnCloseSelector" onclick="return getSelectedPeople();"
                        value="确定" title="提交选择,返回正文界面" />
                    <input type="button" id="btnCloseSelectBar" value="取消" title="返回正文界面" />
                </div>
            </div>
            <table id="bottomTab" class="tb tb2" border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                   <td class="mtd">
					&nbsp;调度部门:
				</td>
				<td class="style1">
					<s:select list="sectionList" listKey="sectionId" listValue="sectionName" headerKey="" headerValue="-请选择-" id="sectionSelector" name="sectionId" theme="simple" cssClass="control-width-40 clearable" cssStyle="width: 152px; height: 26px" ></s:select>
				</td>
				</tr>
				<tr>
				<td class="mtd">
					&nbsp;调度职位:
				</td>
				<td class="style1">
                	<s:select list="#{'':'-请先选择部门-'}" name="postId" id="postSelector" theme="simple" cssClass="control-width-40 clearable input-control" cssStyle="width: 152px; height: 26px"></s:select>
				</td>
                </tr>
                <tr>
                    <td class="mtd" valign="top" style="width: 88px;">
                        <span>申请说明:</span>
                    </td>
                    <td>
                        <input name="txt_Message" type="text" id="txt_Description" style="height: 300px;
                            width: 100%;" />
                    </td>
                </tr>
            </table>
        </div>
            <div style="margin-left: 89px;">
                <input type="submit" name="btnSend" value="提交" id="btnSend" class="o-btn"/>
            <span id="tip" style="color:red;"></span>
        </div>
    </div>
</body>
</html>
